/**
 * Created by li-rz on 16-12-3.
 */
require("../scss/personal_center.scss");

// import fetch and toastr
import "./actions/base.js"
import "./reducers/toastr.js"

import React, {Component, PropTypes} from 'react';
import ReactDOM from 'react-dom';
import PersonalHeader from './components/user/Personal/PersonalHeader/PersonalHeader.jsx';
import PersonalBody from './components/user/Personal/PersonalBody/PersonalBody.jsx';
import PersonFooter from "./components/user/Personal/PersonFooter/PersonFooter.jsx"

// userData
var logined,username,avatar,city,email,sex,sign
var userData = document.getElementById("userData").innerHTML
if(userData.indexOf("NULL") !== -1){
    logined = false
    location.href = "/"         // 跳转到登录注册界面

}else{
    logined = true
    userData = JSON.parse(userData)
    username = userData.username
    avatar = userData.avatar
    sign = userData.sign
    city = userData.city
    email = userData.email
    sex = userData.sex
}

// historiesData
var historiesData = JSON.parse(document.getElementById("historiesData").innerHTML)

// collectData
var collectCoursesData = JSON.parse(document.getElementById("collectCoursesData").innerHTML)

// commentsData
var commentsData = JSON.parse(document.getElementById("commentsData").innerHTML)

// notesData
var notesData = JSON.parse(document.getElementById("notesData").innerHTML)

ReactDOM.render(
    <div>
        <PersonalHeader logined={logined}
                        username={username}
                        avatar={avatar}
        />
        <PersonalBody sign = {sign}
                      city = {city}
                      email = {email}
                      sex = {sex}
                      username={username}
                      avatar={avatar}
                      histories={historiesData}
                      collectCoursesData={collectCoursesData}
                      comments={commentsData}
                      notes={notesData}
        />
        <PersonFooter />
    </div>,
    document.querySelector('#main')
);
